﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Reporting.API.Application.Commands.SaleOrders;
using Reporting.Errorcode;

namespace Reporting.API.Controllers
{
    /// <summary>
    /// 销售订单
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SaleOrderController : ControllerBase
    {
        private readonly IMediator _mediator;

        public SaleOrderController(IMediator mediator)
        {
            _mediator = mediator;
        }


        /// <summary>
        /// 新增生产工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> InsertSaleOrder([FromBody] AddSaleOrderCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 显示所有生产工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetSaleOrder([FromQuery] GetSaleOrderCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 删除生产工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DelSaleOrder([FromQuery] DeleteSaleOrderCommand request)
        {
            return await _mediator.Send(request);
        }


        /// <summary>
        /// 修改生产工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdSaleOrder(UpdateSaleOrderCommand request)
        {
            return await _mediator.Send(request);
        }
    }
}
